package cn.johnyu.adapterdemo03;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/3/21.
 */
public class SimpleAdapterActivity extends ListActivity{
    private List<Map<String,Object>> data=new ArrayList<Map<String, Object>>();

    private void init(){
        Map<String,Object> mp1=new HashMap<String, Object>();
        Map<String,Object> mp2=new HashMap<String, Object>();
        Map<String,Object> mp3=new HashMap<String, Object>();

        mp1.put("show",R.drawable.tf1);
        mp1.put("title","TF1");
        mp1.put("content","contetx.....");

        mp2.put("show",R.drawable.tf2);
        mp2.put("title","TF2");
        mp2.put("content","contetxdfds.....");

        mp3.put("show",R.drawable.tf3);
        mp3.put("title","TF3");
        mp3.put("content","contetxsfd.....");
        data.add(mp1);data.add(mp2);data.add(mp3);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
        SimpleAdapter adapter=new SimpleAdapter(this,data,R.layout.tf_layout,
                new String[]{"show","title","content"},new int[]{R.id.show,R.id.title,R.id.content});
        setListAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Log.i("john", data.get(position).get("content").toString());
    }
}
